<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.tablesorter.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/json.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$("#dialog_lock_flag").dialog({autoOpen:false,modal:true, height: 160, width: 200});
	$("#dialog_unlock_flag").dialog({autoOpen:false,modal:true, height: 160, width: 200});
	$(".lock_click").click(function(){
		$("#lock_id").val($(this).next().val());
		$("#lock_warning_quantity_days1").val($(this).next().next().val());
		$("#lock_safe_quantity_days1").val($(this).next().next().next().val());
		$("#dialog_lock_flag").dialog("open");
	});
	$(".unlock_click").click(function(){
		$("#unlock_id").val($(this).next().val());
		$("#lock_warning_quantity_days2").val($(this).next().next().val());
		$("#lock_safe_quantity_days2").val($(this).next().next().next().val());
		$("#dialog_unlock_flag").dialog("open");
	});
	var product_categories_data = <?=$product_categories?>;
	$(document).mselect(product_categories_data, 'product_categories_id', 'product_categories_id', "<?=isset($_GET['product_categories_id']) ? $_GET['product_categories_id'] : 0?>");
	$(document).mselect(product_categories_data, 'move_cat_id', 'move_cat_id', 0);
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$(".list_table").tablesorter();
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#export_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Warehouse/ExportChecked')?>").submit();
	});
	$("#export_search_btn").click(function(){
		$("#action_form").attr("action", "<?=url('Product::Warehouse/ExportSearch')?>").submit();
	});
	$("#upload_file_btn").click(function(){
		$("#upload_form").submit();
	});
	$("#print_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Warehouse/Print')?>").attr("target", "_blank").submit();
		$("#action_form").attr("target", "");
	});
	$("#create_image_requirement_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Product::Image/Create')?>").submit();
	});
	$("#move_btn").click(function(){
		var ids = new Array();
		$("#list").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		move_cat_id = $("#move_cat_id").val();
		if (! move_cat_id)
		{
			alert('请选择移动分类');
			return false;
		}
		if (! confirm('确定按勾选移动分类？'))
		{
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#form_move_cat_id").val($.toJSON(move_cat_id));
		$("#action_form").attr("action", "<?=url('Product::Warehouse/MoveCategoriesChecked')?>").submit();
	});
	$("#move_search_btn").click(function(){
		move_cat_id = $("#move_cat_id").val();
		if (! move_cat_id)
		{
			alert('请选择移动分类');
			return false;
		}
		if (! confirm('确定按条件移动分类？'))
		{
			return false;
		}
		$("#form_move_cat_id").val($.toJSON(move_cat_id));
		$("#action_form").attr("action", "<?=url('Product::Warehouse/MoveCategoriesSearch')?>").submit();
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form action="" method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
	<table class="form_table">
		<tr>
			<th>产品编号</th>
			<td>
				<input type="text" name="start_number" value="<?=isset($_GET['start_number']) ? $_GET['start_number'] : ''?>" /> to 
				<!-- <input type="text" name="end_number" value="<?=isset($_GET['end_number']) ? $_GET['end_number'] : ''?>" />  --> 前置模糊搜索: A...
			</td>
		</tr>
		<tr>
			<th>产品名称</th>
			<td>
				<input type="text" name="name" value="<?=isset($_GET['name']) ? $_GET['name'] : ''?>" />
			</td>
		</tr>
		<tr>
			<th>供应商名称</th>
			<td>
				<input type="text" name="preferred_provider_name" value="<?=isset($_GET['preferred_provider_name']) ? $_GET['preferred_provider_name'] : ''?>" />
			</td>
		</tr>
		<tr>
			<th>多个编号</th>
			<td><input type="text" name="product_numbers" value="<?=isset($_GET['product_numbers']) ? $_GET['product_numbers'] : ''?>" size="80" /></td>
			<td>说明：多个产品编号用英文逗号分开</td>
		</tr>
		<tr>
			<th>选择分类</th>
			<td><input type="hidden" id="product_categories_id" name="product_categories_id" /></td>
		</tr>
		<tr>
			<th>选择仓库</th>
			<td>
				<select name="warehouse_id">
					<option value="">请选择..</option>
					<? foreach ($warehouse as $w): ?>
					<option value="<?=$w['id']?>" <?if ( ! empty($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id']):?>selected="selected"<?endif;?>><?=$w['name']?></option>
					<? endforeach;?>
				</select>
			</td>
		</tr>
		<tr>
			<th>跟进人</th>
			<td>
				<select name="follow_user_id">
				<option></option>
				<?foreach ($user as $u):?>
				<option value="<?=$u['id']?>" <?if (isset($_GET['follow_user_id']) && $u['id'] == $_GET['follow_user_id'])echo "selected='selected'"?>><?=$u['name']?></option>
				<?endforeach;?>				
				</select>
			</td>
		</tr>
		<tr>
			<th>筛选</th>
			<td>
			<label><input type="checkbox" name="undone" <?if (isset($_GET['undone']))echo "checked=checked";?> /> 资料不全</label>
			<label><input type="checkbox" name="no_follow_user" <?if (isset($_GET['no_follow_user']))echo "checked=checked";?> /> 未跟进</label>
			</td>
		</tr>
		<tr>
			<th>采购状态</th>
			<td colspan="3">
				<?foreach (Q::ini('custom_flag/product_purchase_status') as $ps):?>
				<label><input type="checkbox" name="purchase_status[<?=$ps['value']?>]" value="<?=$ps['value']?>" <?if (isset($_GET['purchase_status'][$ps['value']]) && $_GET['purchase_status'][$ps['value']] == $ps['value'])echo "checked=checked"?> /> <font color="#<?=$ps['color']?>"><?=$ps['name']?></font></label>
				<?endforeach;?>
			</td>
		</tr>
		<tr>
			<th>销售状态</th>
			<td colspan="3">
				<?foreach (Q::ini('custom_flag/product_sales_status') as $ss):?>
				<label><input type="checkbox" name="sales_status[<?=$ss['value']?>]" value="<?=$ss['value']?>" <?if (isset($_GET['sales_status'][$ss['value']]) && $_GET['sales_status'][$ss['value']] == $ss['value'])echo "checked=checked"?> /> <font color="#<?=$ss['color']?>"><?=$ss['name']?></font></label>
				<?endforeach;?>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" name="is_search" id="submit" class="button" value="查询" /></td>
		</tr>
	</table>
</form>
</fieldset>
<table width="100%" class="list_table" id="list">
<thead>
<tr>
	<th width="100">产品编号</th>
	<th>产品名称</th>
	<th width="45">图片</th>
	<th>采购状态</th>
	<th>销售状态</th>
	<th width="100">采购价</th>
	<th width="100">最近采购价</th>
	<th width="100">重量(g)</th>
	<th>首选供应商</th>
	<th>跟进人</th>
	<th width="80">操作</th>
</tr>
</thead>
<tbody>
<? foreach($product as $p):?>
<tr>
	<td><label><input type="checkbox" value="<?=$p['product_basic_id']?>" /> <?=$p['number']?></label></td>
	<td align="left"><?=$p['product_basic_name'];?></td>
	<td>
		<?if ($p['pic_url']):?>
		<?$pretty_photo_number = 0;?>
		<?foreach ($p['pic_url'] as $pp):?>
		<a rel="pretty_photo[<?=$p['id']?>]" href="<?=$pp?>"><?if(!$pretty_photo_number):?><img width="50" src="<?=$pp?>" /><?endif;?></a>
		<?$pretty_photo_number = 1;?>
		<?endforeach;?>
		<?endif;?>
	</td>
	<td><font color="#<?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $p['purchase_status'], 'color')?>"><?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $p['purchase_status'], 'name')?></font></td>
	<td><font color="#<?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $p['sales_status'], 'color')?>"><?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $p['sales_status'], 'name')?></font></td>
	<td><?=sprintf('%.2f', $p['purchase_price'])?></td>
	<td><?=sprintf('%.2f', $p['last_purchase_price'])?></td>
	<td><?=sprintf('%.0f', $p['weight'])?></td>
	<td><?=$p['preferred_provider_name']?></td>
	<td><?=$p['follow_user_name']?></td>
	<td>
		<?if (empty($p['lock_flag'])):?>
		<a class="lock_click">锁定</a>
		<input type="hidden" value="<?=$p['id']?>" />
		<input type="hidden" value="<?=$p['lock_warning_quantity_days']?>" />
		<input type="hidden" value="<?=$p['lock_safe_quantity_days']?>">
		<?else:?>
		<a class="unlock_click">解锁</a>
		<input type="hidden" value="<?=$p['id']?>" />
		<input type="hidden" value="<?=$p['lock_warning_quantity_days']?>" />
		<input type="hidden" value="<?=$p['lock_safe_quantity_days']?>">
		<?endif;?>
		<a href="<?=url('Product::Warehouse/edit', array('id' => $p['product_basic_id']))?>">编辑</a>
	</td>
</tr>
<? endforeach;?>
</tbody>
</table>
<?=$page;?>
<table class="list_table">
	<tr>
		<td rowspan="5"><label><input type="checkbox" id="check_all" /> 全选</label></td>
		<td align="left">
			<form id="upload_form" action="<?=url('Product::Warehouse/Import')?>" method="post" enctype="multipart/form-data">
				导入基本资料：<input type="file" name="product_file" />
				<input type="button" class="button" id="upload_file_btn" value="导入" />
			</form>
		</td>
	</tr>
	<tr>
		<td align="left">导出：
			<input type="button" class="button" id="export_btn" value="按勾选" />
			<input type="button" class="button" id="export_search_btn" value="按条件" />
		</td>
	</tr>
	<tr>
		<td align="left">移动分类：
			<input type="hidden" id="move_cat_id" />
			<input type="button" class="button" id="move_btn" value="按勾选" />
			<input type="button" class="button" id="move_search_btn" value="按条件" />
		</td>
	</tr>
	<tr>
		<td align="left">打印：
			<input type="button" class="button" id="print_btn" value="按勾选" />
		</td>
	</tr>
	<tr>
		<td align="left">创建图片需求单：
			<input type="button" class="button" id="create_image_requirement_btn" value="按勾选" />
		</td>
	</tr>
</table>
<div id="dialog_lock_flag" title="按库存锁定天数更新">
<form method="post" action="<?=url('Product::Warehouse/LockFlagSave')?>">
<input type="hidden" name="id" id="lock_id" value="" />
<p>警告库存锁定天数：<input type="text" name="lock_warning_quantity_days" id="lock_warning_quantity_days1" size="5" /></p>
<p>安全库存锁定天数：<input type="text" name="lock_safe_quantity_days" id="lock_safe_quantity_days1" size="5" /></p>
<p><label><input type="checkbox" name="lock_flag" value="1" /> 锁定</label></p>
<p><input type="submit" value="保存" class="button" /></p>
</form>
</div>
<div id="dialog_unlock_flag" title="库存锁定天数解锁">
<form method="post" action="<?=url('Product::Warehouse/LockFlagSave')?>">
<input type="hidden" name="id" id="unlock_id" value="" />
<p>警告库存锁定天数：<input type="text" name="lock_warning_quantity_days" id="lock_warning_quantity_days2" size="5" /></p>
<p>安全库存锁定天数：<input type="text" name="lock_safe_quantity_days" id="lock_safe_quantity_days2" size="5" /></p>
<p><label><input type="checkbox" name="lock_flag" checked="checked" /> 锁定</label></p>
<p><input type="submit" value="保存" class="button" /></p>
</form>
</div>
<form id="action_form" action="" method="post" target="">
	<input type="hidden" name="url_arr" value='<?=$url_arr?>' />
	<input type="hidden" id="ids" name="ids" value="" />
	<input type="hidden" name="form_move_cat_id" id="form_move_cat_id" value="" />
</form>
<?php $this->_endblock();?>